package com.backend.agtmanaview.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.backend.agtmanaview.mapper.AgtManaViewMapper;
import com.backend.agtmanaview.domain.AgtManaView;
import com.backend.agtmanaview.service.IAgtManaViewService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 租赁合同管理Service业务层处理
 * 
 * @author fusi
 * @date 2024-10-13
 */
@Service
public class AgtManaViewServiceImpl implements IAgtManaViewService 
{
    @Autowired
    private AgtManaViewMapper agtManaViewMapper;

    /**
     * 查询租赁合同管理
     * 
     * @param leaseAgreementId 租赁合同管理主键
     * @return 租赁合同管理
     */
    @Override
    public AgtManaView selectAgtManaViewByLeaseAgreementId(Long leaseAgreementId)
    {
        return agtManaViewMapper.selectAgtManaViewByLeaseAgreementId(leaseAgreementId);
    }

    /**
     * 查询租赁合同管理列表
     * 
     * @param agtManaView 租赁合同管理
     * @return 租赁合同管理
     */
    @Override
    public List<AgtManaView> selectAgtManaViewList(AgtManaView agtManaView)
    {
        return agtManaViewMapper.selectAgtManaViewList(agtManaView);
    }

    /**
     * 新增租赁合同管理
     * 
     * @param agtManaView 租赁合同管理
     * @return 结果
     */
    @Override
    @Transactional
    public int insertAgtManaView(AgtManaView agtManaView)
    {
        agtManaView.setLeaseAgreementId(agtManaViewMapper.getMaxLeaseAgreementId() + 1);
        int a = agtManaViewMapper.insertLeaseAgreement(agtManaView);
        int b = agtManaViewMapper.insertMbuserSignAgreement(agtManaView);
        int c = agtManaViewMapper.insertAgreementCorrespondRoom(agtManaView);
        return a>0 && b>0 && c>0?a+b+c:0;
    }

    /**
     * 修改租赁合同管理
     * 
     * @param agtManaView 租赁合同管理
     * @return 结果
     */
    @Override
    @Transactional
    public int updateAgtManaView(AgtManaView agtManaView)
    {
        int b = 0,c = 0;
        int a = agtManaViewMapper.updateLeaseAgreement(agtManaView);
        if(agtManaView.getMobileUserId() != null)
            b = agtManaViewMapper.updateMbuserSignAgreement(agtManaView);
        if(agtManaView.getRoomId() != null)
            c = agtManaViewMapper.updateAgreementCorrespondRoom(agtManaView);
        return a>0?a+b+c:0;
    }

    /**
     * 批量删除租赁合同管理
     * 
     * @param leaseAgreementIds 需要删除的租赁合同管理主键
     * @return 结果
     */
    @Override
    public int deleteAgtManaViewByLeaseAgreementIds(Long[] leaseAgreementIds)
    {
        return agtManaViewMapper.deleteAgtManaViewByLeaseAgreementIds(leaseAgreementIds);
    }

    /**
     * 删除租赁合同管理信息
     * 
     * @param leaseAgreementId 租赁合同管理主键
     * @return 结果
     */
    @Override
    public int deleteAgtManaViewByLeaseAgreementId(Long leaseAgreementId)
    {
        return agtManaViewMapper.deleteAgtManaViewByLeaseAgreementId(leaseAgreementId);
    }
}
